-
Notifications
You must be signed in to change notification settings - Fork 2.8k
add Sa token ehcache plugin #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
您好,我已对 PR #811 进行了代码审查,以下是一些发现和建议:
-
依赖版本管理:
sa-token-demo/sa-token-demo-ehcache/pom.xml
中sa-token.version
硬编码为1.44.0
,建议统一版本管理,例如在父pom.xml
中定义sa-token.version
并在所有子模块中引用,并与主项目的 Spring Boot 版本保持一致。 -
Ehcache
CacheManager
生命周期管理: 在SaMapPackageForEhcache
中,CacheManager
是一个static final
字段,通过EhcacheConfig.CreateCacheManager()
初始化。这意味着CacheManager
在应用程序启动时创建一次,并在整个应用程序生命周期中保持活动状态。虽然EhcacheConfig
提供了CloseCacheManager
方法,但在SaMapPackageForEhcache
中并没有看到显式的关闭操作。这可能导致资源泄漏,尤其是在应用程序关闭时。建议在应用程序关闭时(例如通过 Spring 的@PreDestroy
或DisposableBean
接口)显式关闭CacheManager
。 -
Ehcache 缓存配置:
SaMapPackageForEhcache
中CacheConfigurationBuilder
使用ResourcePoolsBuilder.heap(Integer.MAX_VALUE)
和ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(Long.MAX_VALUE))
。这意味着缓存将使用堆内存,并且永不过期。对于 Sa-Token 这种需要管理 Token 过期时间的场景,这显然是不合理的。SaTokenDaoEhcache
中的set
和update
方法需要将timeout
参数转换为 Ehcache 的过期策略。 -
SaTokenDaoEhcache
实现:getTimeout
方法返回-1
,表示永不过期,这与 Sa-Token 的设计不符。set
和update
方法需要将 Sa-Token 的timeout
参数转换为 Ehcache 的过期时间。get
方法中,如果cache.get(key)
返回null
,应该返回null
,而不是null
字符串。searchData
方法的实现是遍历所有 key,对于 Ehcache 来说,这可能不是最高效的查询方式,可以考虑优化。 -
代码规范和可读性:
GlobalException.java
中的e.printStackTrace()
在生产环境中不建议直接使用,应该使用日志框架记录异常。 -
测试: PR 中只包含了 demo 模块,没有看到
sa-token-ehcache
模块的单元测试或集成测试。对于一个新的插件模块,应该有充分的测试来验证其功能和稳定性,特别是 Ehcache 的缓存行为和过期时间管理。
但 Ehcache 缓存的过期时间管理是核心问题,需要确保 Sa-Token 的过期机制能够正确映射到 Ehcache 上,并且需要添加充分的测试。
您好,非常感谢您对pr811的审查意见。对于这份意见,我有一些疑问和修改方案,还麻烦您看一下是否合理:
以上是我的疑问和修改方案,最后还是非常感谢您,并希望您能进一步指教 |
1.理解您的考虑,当前插件都采用 spring-boot-starter-parent 作为父 pom,确实统一风格很重要。如果后续插件数量增多或依赖管理变复杂,可以考虑通过 BOM 或 properties 方式在父 pom 统一管理版本,既不影响现有风格,也便于后期维护。 最后感谢您的回复,我考虑问题不周,多多包涵。再次感谢您的回复。 |
在destory的注释中有提及显式关闭的时机。请问开发插件的pr 合并的规则是什么呢,除了demo文件,其他文件比如插件的文档和独立测试包也要包括在这个pr中么 |
https://github.com/sa-tokens/sa-token-three-plugin 中有第三方插件的仓库,应该可以提交PR到这里面。或者直接提交到插件包下面吧。我也不太清楚。其他的文件应该也包含在此次PR中 |
好的,我去研究一下这个网站,谢谢了~ |
add ehcache plugin for satoken. This pr lncludes plugin module and demo module.